package pl.enigmatic.parser.string;

import pl.enigmatic.util.Arrays;
import pl.enigmatic.util.Reflection;


@SuppressWarnings({ "rawtypes", "unchecked" })
public class PrimitiveArrayConverter extends Converter {

	private final Converter converter;

	public PrimitiveArrayConverter(final Class clazz) {
		final Class<?> base = Reflection.arrayBase(clazz);
		final int depth = Reflection.arrayDepth(clazz);
		converter = createDefaultConverter(Reflection.arrayType(Reflection.wrapper(base), depth));
	}

	@Override
	public Object convert(final Object value) {
		return Arrays.convert(converter.convert(value));
	}

	@Override
	public String convertBack(final Object value) {
		return (String) converter.convertBack(Arrays.convert(value));
	}

}
